﻿using DevExpress.XtraGrid.Demos.util;
using DiaoPaiDaYin;
using DXApplicationTangche.DTO;
using DXApplicationTangche.model;
using DXApplicationTangche.UC.门店下单.DTO;
using DXApplicationTangche.Utils;
using mendian;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.service
{
    /// <summary>
    /// 设计点服务
    /// </summary>
    public class ItemService
    {
        
        public static Boolean SaveExcelToTable(String barcode, List<DTO款式配置设计点展现> 设计点图片Dtos, String styleid, String stylename, bool hasTitle = false)
        {
            ExcelAndPath excelAndPath = ExcelUtil.getExcelDataAndPath("");
            if (excelAndPath == null)
            {
                return false;
            }
            DataSet result = excelAndPath.DataSet;
            List<设计点Excel格式> Exceldtos = new List<设计点Excel格式>();
            result.Tables[0].Rows.RemoveAt(0);
            foreach (DataRow dr in result.Tables[0].Rows)
            {
                if (!String.IsNullOrWhiteSpace(dr[0].ToString()))
                {
                    Exceldtos.Add(new 设计点Excel格式(dr,1));
                }
            }
            //Exceldtos = DataTableExtend.ToDataList<设计点Excel格式>(result.Tables[0]);
            List<DTO款式配置设计点展现> Showdtos = new List<DTO款式配置设计点展现>();
            foreach (设计点Excel格式 dto in Exceldtos)
            {
                Showdtos.Add(new DTO款式配置设计点展现(dto, styleid, stylename));
            }
            款式配置设计点数据清洗Model model = new 款式配置设计点数据清洗Model(Showdtos).buildOldId(设计点图片Dtos);
            //String str = RestCall.PostHttp(URL.接口url + "/style/saveStyleDesign", FunctionHelper.JsonSerialization(model));
            String str = RestCall.PostHttp(URL.接口url + "/style/saveStyleDesign?barcode="+ barcode, FunctionHelper.JsonSerialization(model));
            
            return true;
        }
        /// <summary>
        /// 导出Excel用
        /// </summary>
        /// <param name="Dtos"></param>
        /// <returns></returns>
        public static List<设计点Excel格式> ListForExcel(List<DTO款式配置设计点展现> Dtos)
        {
            List<设计点Excel格式> Exceldtos = new List<设计点Excel格式>();
            Dtos.Sort(new CComparer());
            String item_value = "";
            foreach (DTO款式配置设计点展现 Dto in Dtos)
            {
                item_value = Dto.DEFAULT_VALUE;
                if (Dto.C_ITEM_VALUE == item_value)
                {
                    Exceldtos.Add(new 设计点Excel格式(Dto, true));
                }
                else
                {
                    Exceldtos.Add(new 设计点Excel格式(Dto, false));
                }
            }
            return Exceldtos;
        }
        
        public static List<DTODesignPoints> SortItemList(List<DTODesignPoints> Dto设计点s)
        {
            List<DTODesignPoints> Dtos = Dto设计点s;
            DTODesignPoints Dto4SMO = new DTODesignPoints();
            DTODesignPoints Dto4SMC = new DTODesignPoints();
            DTODesignPoints Dto4SMP = new DTODesignPoints();
            DTODesignPoints Dto4SMS = new DTODesignPoints();
            DTODesignPoints Dto4SMT = new DTODesignPoints();

            foreach (DTODesignPoints dto in Dto设计点s)
            {
                if (dto.itemValue.Equals("4SMO"))
                //if (dto.ITEM_VALUE.Equals("4SMO") || dto.ITEM_VALUE.Equals("4SMC") || dto.ITEM_VALUE.Equals("4SMP") || dto.ITEM_VALUE.Equals("4SMS") || dto.ITEM_VALUE.Equals("4SMT"))
                {
                    Dtos.Remove(dto);
                    Dtos.Add(dto);
                    break;
                }
            }
            foreach (DTODesignPoints dto in Dto设计点s)
            {
                if (dto.itemValue.Equals("4SMC"))
                //if (dto.ITEM_VALUE.Equals("4SMO") || dto.ITEM_VALUE.Equals("4SMC") || dto.ITEM_VALUE.Equals("4SMP") || dto.ITEM_VALUE.Equals("4SMS") || dto.ITEM_VALUE.Equals("4SMT"))
                {
                    Dtos.Remove(dto);
                    Dtos.Add(dto);
                    break;
                }
            }
            foreach (DTODesignPoints dto in Dto设计点s)
            {
                if (dto.itemValue.Equals("4SMP"))
                //if (dto.ITEM_VALUE.Equals("4SMO") || dto.ITEM_VALUE.Equals("4SMC") || dto.ITEM_VALUE.Equals("4SMP") || dto.ITEM_VALUE.Equals("4SMS") || dto.ITEM_VALUE.Equals("4SMT"))
                {
                    Dtos.Remove(dto);
                    Dtos.Add(dto);
                    break;
                }
            }
            foreach (DTODesignPoints dto in Dto设计点s)
            {
                if (dto.itemValue.Equals("4SMS"))
                //if (dto.ITEM_VALUE.Equals("4SMO") || dto.ITEM_VALUE.Equals("4SMC") || dto.ITEM_VALUE.Equals("4SMP") || dto.ITEM_VALUE.Equals("4SMS") || dto.ITEM_VALUE.Equals("4SMT"))
                {
                    Dtos.Remove(dto);
                    Dtos.Add(dto);
                    break;
                }
            }
            foreach (DTODesignPoints dto in Dto设计点s)
            {
                if (dto.itemValue.Equals("4SMT"))
                //if (dto.ITEM_VALUE.Equals("4SMO") || dto.ITEM_VALUE.Equals("4SMC") || dto.ITEM_VALUE.Equals("4SMP") || dto.ITEM_VALUE.Equals("4SMS") || dto.ITEM_VALUE.Equals("4SMT"))
                {
                    Dtos.Remove(dto);
                    Dtos.Add(dto);
                    break;
                }
            }
            return Dtos;

        }
    }
}
